<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="content-type" content="text/html;charset=utf-8" />
  <meta name="description" content="Twitter bio and profile search, even allows you to limit by your personalized friends and followers." />
  <meta name="keywords" content="twitter, bio, profile, search, index, description, location" />
  <title>找人么</title>
  <link href="css/css1.css" media="screen" rel="stylesheet" type="text/css" />
  <link href="css/css2.css" media="screen" rel="stylesheet" type="text/css" />
  <link href="css/pie.css" media="screen" rel="stylesheet" type="text/css" />
  <!--[if IE]><script language="JavaScript" type="text/javascript" src="js/excanvas.js"></script><![endif]-->
  <script language="JavaScript" type="text/javascript" src="js/jquery.js"></script>
  <script language="JavaScript" type="text/javascript" src="js/jquery.flot.js"></script>
  <script language="JavaScript" type="text/javascript" src="js/jquery.flot.pie.js"></script>
  <script type="text/javascript">
	window.ssss = new Array()
        var index=0;
	function getImgs(uids){
            if(uids){
              while( index < uids.length) {
		aTag = "<a href=\"sq.php?qzoneid=" + uids[index] + "\" target=\"_blank\">";
		window.ssss[index] = aTag + "<img width='48' height='48' border=0 src='http://qlogo2.store.qq.com/qzonelogo/" + uids[index] + "/1/0/favicon.ico' /></a>";
		index = index+1
              }
            }
	}
  </script>
</head>
<?php 
  $type = $_GET['choose'];
  if($_GET[searchid]){
     if ($type == 'qqshuqian')
       $searchid = $_GET[query];
     else
       $searchid = $_GET[query];
     echo "<script language='javascript'>";
     echo "location='http://192.168.1.100/souren/sq.php?qzoneid=$searchid'";
     echo "</script>";
  }
  function displayQQShuqianElem($id, $uName, $imgUrl, $imgAlt, $modtime, $articleNum)
  {
    list($d, $t) = split(" ", $modtime);
    echo             "<div class='user_profile'>
                        <table align='center'>
                          <tr>
                            <td>
                              <a href='sq.php?qqid=" . "$id" . "'>
                                <img width='48' height='48' src='" . "$imgUrl" . "' onError='this.src='" . "$imgAlt" . "' />
                              </a>
                            </td>
                            <td width='200' valign='top'>
                              <a href='sq.php?qqid=" . "$id" . "' target='_blank'><strong>" . "$uName" . "</strong></a>
                              <br />
                              QQ号:&nbsp;" . "$id" . "
                              <br />
                            </td>
                            <td width='400' valign='top'>
                              <span class='label'></span>
                              <span class='bio_text'>这里填充此人的关键字摘要</span>
                              <span class='last_tweet_time'>&nbsp;</span>
                            </td>
                            <td valign='top'>
                              <table class='user_stats' >
                                <tr>
                                  <td align='left' width='50px'>更新时间:</td>
                                  <td align='right'>" . "$d" . "</td>
                                </tr>
                                <tr>
                                  <td align='left' width='50px'>文章数目:</td>
                                  <td align='right'>" . "$articleNum" . "</td>
                                </tr>
                                <tr>
                                  <td align='left' width='50px'>朋友:</td>
                                  <td align='right'>21</td>
                                </tr>
                              </table>
                            </td>
                          </tr>
                        </table>
                      </div>";
  }
  function displayQzoneElem($n, $id, $uName, $qzoneDescription, $qzoneName, $bioDescription, $modtime, $articleNum, $cat_name_json, $weight_json)
  {
    list($d, $t) = split(" ", $modtime);
    echo             "<div class='user_profile'>
                        <table align='center'>
                          <tr>
                            <td>
                               <div>
                                 <div style='float:left;'>
                                   <iframe src=\"javascript:parent.ssss[" . "$n" . "]\" width='50' height='50' frameborder='0' scrolling='no' marginheight='0' marginwidth='0'></iframe>
                                 </div>
                                 <div id='graph" . "$n" . "' class='pie-graph' onclick=\"javascript:window.open('sq.php?qzoneid=" . "$id" . "', 'pie_chart')\">
                               </div>
                            </td>
                            <td width='200' valign='top'>
                              <br />
                              <a href='sq.php?qzoneid=" . "$id" . "' target='_blank'><strong>" . "$uName" . "</strong></a>
                              <br />
                              QQ号:&nbsp; " . "$id" . "
                              <br />
                              Qzone:&nbsp;
                              <a href='http://feeds.qzone.qq.com/cgi-bin/cgi_rss_out?uin=" . "$id" . "' title='" . "$qzoneDescription" . "' target='_blank'>
                                " . "$qzoneName" . "
                              </a>
                            </td>
                            <td width='400' valign='top'>
                              <span class='label'></span>
                              <span class='bio_text'>
                                  " . "$bioDescription" . "
                              </span>
                              <span class='last_tweet_time'>&nbsp;</span>
                            </td>
                            <td valign='top'>
                              <table class='user_stats'>
                                <tr>
                                  <td align='left' width='50px'>更新时间:</td>
                                  <td align='right'>" . "$d" . "</td>
                                </tr>
                                <tr>
                                  <td align='left' width='50px'>文章数目:</td>
                                  <td align='right'>" . "$articleNum" . "</td>
                                </tr>
                              </table>
                            </td>
                          </tr>
                        </table>
                      </div>";

		  /*I have to acknowledge this is a hack. */
                  echo "<script language='JavaScript' type='text/JavaScript'> 
                             var cat_name_js = $cat_name_json;
                             var weight_js = $weight_json;
                             var data = [];
                             for(var i=0; i<cat_name_js.length; ++i)
                             {
                                        data[i] = { label: cat_name_js[i], data: weight_js[i] }
                             }
                             /*alert('hahahah');*/
                             $.plot($(\"#graph$n\"), data,
                                {
                                    series: {
                                        pie: {
                                                show: true,
                                                radius: 0.9,
                                                label: {
                                                        show: false,
                                                        radius: 3/4,
                                                        formatter: function(label, series){
                                                                var ret = '<div style=\"font-size:8pt;text-align:center;padding:2px;color:white;\">' + label + '<br />' + Math.round(series.percent) + '%</div>';
                                                                /*alert(ret);*/
                                                                return ret;
                                                        },
                                                background: {                                           
                                                        opacity: 0.5,
                                                        color: '#000'
                                                        }
                                                }
                                        }
                                    },
                                    legend: {
                                        show: false
                                    }
                                });
                             /*alert(cat_name_js[2]);*/
                             /*alert(weight_js[2]); */
                          </script>";
  }
?>

<body>
 <div class="container">
  <div class="wrapper">
    <table height="96" border="0">
      <tr>
        <td width="960" height="80" bordercolor="#FFFFFF">
          <span style="float:left;"><img src="img/i.gif" width="228" height="67"></span>
          <!-- <span style="float:left;"></span> -->
          <form name="form1" method="get" action="search.php">
            <input name="query" type="text" id="query" value="<?php  echo $_GET[query]?>" size="47" maxlength="100">
            <span style="margin:auto;">
              <input name="submit" type=submit class="stb" id="stb" onClick="if(this.form.query.value=='')return false" value="再试试">
            </span>
            <a href="supersearch.php">高级搜索</a>
            <br/> <br/>
            <input type="radio" name="choose" value="qzone" <?php if ($type == "qzone") echo "checked" ?> > QZone
            <input type="radio" name="choose" value="qqshuqian" <?php if ($type == "qqshuqian") echo "checked" ?> > QQ书签
             <input type="checkbox" name="searchid" value="searchid"<?php  if($_GET['searchid']) echo "checked"?> >搜索ID</input>
               <input type="checkbox" name="searchname" value="searchname"<?php  if($_GET['searchname']) echo "checked"?> >搜索名字</input>
          </form>
        </td>
      </tr>
    </table>
    <br/>
    <table width="900" border="0">
      <tr bgcolor="#E8F3FF">
        <td width="101" height="25"><a href="#">按相关度排序</a></td>
        <td width="98"><a href="#">按活跃度排序</a></td>
        <td width="750">&nbsp;</td>
      </tr>
    </table>

    <div class="content">
      <div class="right" id="twit_auth"> </div>
      <div id="search_hits">
        <?php
          $con = mysql_connect("127.0.0.1","root","123");
          if (!$con)
            die('Could not connect: ' . mysql_error());
          if ($type == 'qqshuqian')
            @mysql_select_db("crawlqq", $con);
          else
            @mysql_select_db("crawlqzone", $con);
          @mysql_query("set names utf-8");

          if(!isset($_GET["page"]) || !is_numeric($_GET["page"])) {
            $page=1;
          }else{
            $page=intval($_GET["page"]);
          }

          $querystr = '';
          if($_GET['query']){
           if($_GET['searchname']){

              $time_start = microtime();
              $sql = mysql_query("select count(seq) from user where uName='" . $_GET['query'] . "'", $con);
              if ( $dbres = mysql_fetch_array($sql) )
                 $total = $dbres[0];
              else
                 $total = 0;
              $total_limit = ($total > 1000 ? 1000 : $total);
              $pagesize=20;

              if($total%$pagesize==0){
                $pagecount=intval($total_limit/$pagesize);
              }else{
                $pagecount=ceil($total_limit/$pagesize);
              }
              if (!$pagecount)
                $pagecount = 1;

              if ($type == 'qzone')
                 $querystr = "select id, uName, qzoneName, qzoneDescription, articleNum, done, modtime, seq from user where uName='" . $_GET['query'] . "' order by articleNum desc limit ".($page-1)*$pagesize.",$pagesize";
              else if ($type == 'qqshuqian')
                 $querystr = "select id, uName, articleNum, imgUrl, imgAlt, done, modtime, seq from user where uName='" . $_GET['query'] . "' order by articleNum desc limit ".($page-1)*$pagesize.",$pagesize";


              $sql = mysql_query($querystr, $con);
              $res2 = array();
              while( $dbres = mysql_fetch_array($sql) ) {
                $res2[] = array($dbres[0], $dbres[1], $dbres[2], $dbres[3], $dbres[4], $dbres[5], $dbres[6]);
                $uids[] = $dbres[0];
              }
              if ($type == "qzone" && $uids) {
                $js_str = "<script>getImgs( [" . join(" ,", $uids) . "] )</script>";
                echo $js_str;
              }
              $uName = $_GET['query'];
              $time_used = microtime() - $time_start;

              foreach ( $res2 as $dbres ) {
                 if ($type == "qqshuqian") {
                   $id = $dbres[0];
                   $articleNum=$dbres[2];
                   $imgUrl=$dbres[3];
                   $imgAlt=$dbres[4];
                   displayQQShuqianElem($id, $uName, $imgUrl, $imgAlt, $modtime, $articleNum);
                 } else if ($type == "qzone") {
                   $id = $dbres[0];
                   $qzoneName=$dbres[2];
                   $qzoneDescription=$dbres[3];
                   $articleNum=$dbres[4];
                    //get the userpie data
                   $cat_name = array();
                   $weight = array();
                   $bioDescription = "";
                   $pie_result = mysql_query("select * from userpie where id=$id", $con);
                   while($roww = mysql_fetch_array($pie_result)) {
                     array_push($cat_name, $roww['cat_name']);
                     array_push($weight, count(explode('@@', $roww['blog_ids'])));
                     $bioDescription .= $roww['cat_name'] . ': ';
                     $bioDescription .= join(' ', array_slice(explode('@@', $roww['keywords']), 0, 5));
                     $bioDescription .= "<br />\n";
                   }
                   $cat_name_json = json_encode($cat_name);
                   $weight_json = json_encode($weight);
                   displayQzoneElem($n, $id, $uName, $qzoneDescription, $qzoneName, $bioDescription, $modtime, $articleNum, $cat_name_json, $weight_json);
                 }
                 $n++;
              }
           } else {
            include("sphinxapi.php");
            $mode = SPH_MATCH_ALL;
            //$host = "localhost";
            $host = "192.168.1.100";
            $port = 3312;
            if ($type == 'qzone')
                $index = "qzone_account_idx";
            else if ($type == 'qqshuqian')
                $index = "qqshuqian_account_idx";
            $groupby = "";
            $groupsort = "@group desc";
            $filter = "group_id";
            $filtervals = array();
            $distinct = "";
            $sortby = "";
            $limit = 20;
            $offset = $limit * $page;
            $ranker = SPH_RANK_PROXIMITY_BM25;
            $cl = new SphinxClient ();
            $cl->SetServer ( $host, $port );
            $cl->SetConnectTimeout ( 1 );
            $cl->SetWeights ( array ( 100, 1 ) );
            $cl->SetMatchMode ( $mode );
            if ( count($filtervals) ) $cl->SetFilter ( $filter, $filtervals );
            if ( $groupby ) $cl->SetGroupBy ( $groupby, SPH_GROUPBY_ATTR, $groupsort );
            if ( $sortby ) $cl->SetSortMode ( SPH_SORT_EXTENDED, $sortby );
            if ( $sortexpr ) $cl->SetSortMode ( SPH_SORT_EXPR, $sortexpr );
            if ( $distinct ) $cl->SetGroupDistinct ( $distinct );
            if ( $limit ) $cl->SetLimits ( $offset, $limit, ( $limit>1000 ) ? $limit : 1000 );
            $cl->SetRankingMode ( $ranker );
            $cl->SetArrayResult ( true );
            $res = $cl->Query ( $_GET['query'], $index );


            if ( $res===false ) {
              //print "Query failed: " . $cl->GetLastError() . ".\n";
              echo "<div align=center>抱歉，没有记录！</div>";
            } else {
              if (false) {
                if ( $cl->GetLastWarning() )
                  print "WARNING: " . $cl->GetLastWarning() . "\n\n";
              }
              $total_limit = $res[total];
              $total = $res[total_found];
              $time_used = $res[time];

              $pagesize=20;
              if($total%$pagesize==0){
                $pagecount=intval($total_limit/$pagesize);
              }else{
                $pagecount=ceil($total_limit/$pagesize);
              }
              if (!$pagecount)
                $pagecount = 1;

              if($total==0){
                echo "<div align=center>抱歉，没有记录！</div>";
              } else {
                if ( is_array($res["matches"]) ) {
                  // fetch from db
                  $seqs = array();
                  $uids = array();
                  foreach ( $res["matches"] as $docinfo ) {
                    $seqs[] = "$docinfo[id]";
                  }
                  if ($type == 'qzone')
                    $querystr = "select id, uName, qzoneName, qzoneDescription, articleNum, done, modtime, seq from user where seq=" . join(" or seq=", $seqs);
                  else if ($type == 'qqshuqian')
                    $querystr = "select id, uName, articleNum, imgUrl, imgAlt, done, modtime, seq from user where seq=" . join(" or seq=", $seqs);

                  $sql = mysql_query($querystr, $con);
                  $res2 = array();
                  while( $dbres = mysql_fetch_array($sql) ) {
                    $res2[$dbres[7]] = array($dbres[0], $dbres[1], $dbres[2], $dbres[3], $dbres[4], $dbres[5], $dbres[6]);
                    //print "$dbres[0], ";
                  }
                  if ($type == "qzone") {
                    for($ii = 0; $ii < count($seqs); $ii++) {
                      $uids[$ii] = $res2[$seqs[$ii]][0];
                    }
                    $js_str = "<script>getImgs( [" . join(" ,", $uids) . "] )</script>";
                    echo $js_str;
                  }

                  $n = 0;
                  foreach ( $res["matches"] as $docinfo ) {
                    //print "$n. doc_id=$docinfo[id], weight=$docinfo[weight]";
                    $userseq = $docinfo[id];

                    if ($res2) {
                      $id=$res2[$userseq][0];
                      $uName=$res2[$userseq][1];
                      $done=$res2[$userseq][5];
                      $modtime=$res2[$userseq][6];

                      if ($type == "qqshuqian") {
                        $articleNum=$res2[$userseq][2];
                        $imgUrl=$res2[$userseq][3];
                        $imgAlt=$res2[$userseq][4];
                        displayQQShuqianElem($id, $uName, $imgUrl, $imgAlt, $modtime, $articleNum);
                      } else if ($type == "qzone") {
                        $qzoneName=$res2[$userseq][2];
                        $qzoneDescription=$res2[$userseq][3];
                        $articleNum=$res2[$userseq][4];
                         //get the userpie data
                        $cat_name = array();
                        $weight = array();
                        $bioDescription = "";
                        $pie_result = mysql_query("select * from userpie where id=$id", $con);
                        while($roww = mysql_fetch_array($pie_result)) {
                          array_push($cat_name, $roww['cat_name']);
                          array_push($weight, count(explode('@@', $roww['blog_ids'])));
                          $bioDescription .= $roww['cat_name'] . ': ';
                          $bioDescription .= join(' ', array_slice(explode('@@', $roww['keywords']), 0, 5));
                          $bioDescription .= "<br />\n";
                        }
                        $cat_name_json = json_encode($cat_name);
                        $weight_json = json_encode($weight);
                        displayQzoneElem($n, $id, $uName, $qzoneDescription, $qzoneName, $bioDescription, $modtime, $articleNum, $cat_name_json, $weight_json);
                      }
                    }
                    $n++;
                  }
                }
              }
            }
           }
          }
          mysql_close($con);
        ?>

      </div>
    </div>
        

    <div class="content">
      <div class="right" id="twit_auth"> </div>
      <div id="search_hits">
        <table width="550" height="25" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td width="35">
              <div align="left" class="ed">
                搜到&nbsp;<?php echo $total;?>&nbsp;位网友&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;（用时 <?php echo $time_used?>秒）
                
              </div>
            </td>
            <td width="350"> <div align="left">
第&nbsp;<?php echo $page;?>&nbsp;页/共&nbsp;<?php echo $pagecount;?>&nbsp;页</div>
</td>
            <?php
              if($page>1) $pre_page_num=$page-1;
              else $pre_page_num=1;
              if($page<$pagecount) $next_page_num=$page+1;
              else $next_page_num=$pagecount;
            ?>
            <td width="199">
              <div align="right">
                <a href="<?php echo $_SERVER["PHP_SELF"]?>?query=<?php echo $_GET[query]?>&searchname=<?php echo $_GET[searchname] ?>&choose=<?php echo $_GET[choose]?>&page=1" class="a1">首页</a>&nbsp;
                <a href="<?php echo $_SERVER["PHP_SELF"]?>?query=<?php echo $_GET[query]?>&searchname=<?php echo $_GET[searchname] ?>&choose=<?php echo $_GET[choose]?>&page=<?php echo $pre_page_num?>" class="a1">上一页</a>&nbsp;
                <a href="<?php echo $_SERVER["PHP_SELF"]?>?query=<?php echo $_GET[query]?>&searchname=<?php echo $_GET[searchname] ?>&choose=<?php echo $_GET[choose]?>&page=<?php echo $next_page_num?>" class="a1">下一页</a>&nbsp;
                <a href="<?php echo $_SERVER["PHP_SELF"] ?>?query=<?php echo $_GET[query]?>&searchname=<?php echo $_GET[searchname] ?>&choose=<?php echo $_GET[choose]?>&page=<?php echo $pagecount?>" class="a1">尾页</a>
              </div>
            </td>
          </tr>
        </table>
      </div>
      <table align="center" class="tools">
       <tr>
        <td valign="top">
         <a href="#">意见反馈</a> &nbsp;&nbsp; <a href="#">帮助中心</a>&nbsp;&nbsp; <a href="#">网站合作</a>&nbsp;&nbsp; <a href="#">关于我们</a>&nbsp;&nbsp; <a href="#">联系方式</a>
         <br /> &copy; 2009 zhaoren.me
         <a href="#" target=_blank class=g>沪ICP证xxxx号</a>
         <span class=ba>&nbsp;</span>
        </td>
       </tr>
      </table>
    </div>
   </div>
  </body>
</html>
